Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
Sequelize "object" does not have increment function

I am using generate sequelize tables from Django generated models with sequelize-auto in my project. so far so good. I wrote the code to update the rank if I see a url again.

const findLink = async (link) =>
  Link.findOne({
    where: {
      url: link,
    },
    raw: true,
  });
// eslint-disable-next-line no-use-before-define
const insertEvent = async (link, tweetText) => {
  // Sync Database table before reading
  await sequelize.sync();
  findLink(link).then((url) => {
    if (url) {
      url.increment("rank", {by: 1}).then(()=>{
      Event.create({
        url_id: url.id,
        tweet_text: tweetText,
        created_at: new Date(),
        updated_at: new Date(),
      })
    });

    } else {
      Link.create({
        url: link,
        rank: 0,
        created_at: new Date(),
        updated_at: new Date(),
      }).then((newLink) => {
        Event.create({
          url_id: newLink.id,
          tweet_text: tweetText,
          created_at: new Date(),
          updated_at: new Date(),
        });
      });
    }
  });
};

But the problem is that when It execute url.increment("rank", {by: 1}) it says that url does not have increment function.

But according to documentation it is clearly stated here. Please let me know if I am doing something wrong? I have searched the internet but I could not find any thing relative. I can update the value with duplicate look up but I am looking for a way If I could update the already found object instead of searching it again.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are using raw queries

const findLink = async (link) =>
  Link.findOne({
    where: {
      url: link,
    },
    raw: true,
  });

It doesn't return an instance of the Model

See https://sequelize.org/master/manual/raw-queries.html

Edit:

By default the function will return two arguments - a results array, and an object containing metadata (such as amount of affected rows, etc).

A second option is the model. If you pass a model the returned data will be instances of that model.

// Callee is the model definition. This allows you to easily map a query to a predefined model
const projects = await sequelize.query('SELECT * FROM projects', {
  model: Projects,
  mapToModel: true // pass true here if you have any mapped fields
});
// Each element of `projects` is now an instance of Project

So the mapToModel option might also work

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!